package com.ynny.chapter04.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class R {

    private Integer code;
    private String msg;
    private Object  data;

    
    public static R ok(Object data) {
        return new R(200, "success", data);
    }

    public static R ok() {
        return new R(200, "success", null);
    }

    public static R error(Integer code, String msg) {
        return new R(code, msg, null);
    }

    public static R fail(String msg, Object data) {
        return new R(500, msg, data);
    }

    public R setData(Object data) {
        this.data = data;
        return this;
    }
}